var $certusUtils;
var $$scope;
var $$http;
var proId = 0;
var $CertusJsonAjax;
var projectType;
var tProjMemberId;
var proBaseInfo;
var leftMenu;
var userId;
function toLoadHtml(flag, kid) {
    //项目仪表盘页面
    $("#rightContainer").empty();
    $$scope.htmlxx = "";
    if (flag == 1) {
        $("#rightContainer").load("project/proinfo/proIndex.html");
    } else if (flag == 2) {
        //添加项目指标
        $("#rightContainer").load("project/proinfo/addWarn.html", function () {
            toAddWarn($certusUtils);
        });
    } else if (flag == 3) {
        //修改项目指标
        $("#rightContainer").load("project/proinfo/updateWarn.html", function () {
            toUpdateWarn($certusUtils, kid);
        });
    } else if (flag == 4) {
        //okr 主页面
        $("#rightContainer").load("proinfo/okr.html", function () {
            //切换tab
            toReturnJump(kid)
        });
    } else if (flag == 5) {
        //客户管理
        $("#rightContainer").load("project/proinfo/customer.html", function () {
            findCusList($certusUtils);
        })
    } else if (flag == 6) {
        //查看联系人
        $("#rightContainer").load("project/proinfo/customerLxr.html", function () {
            findLxrList($certusUtils, kid);
        });
    } else if (flag == 7) {
        //更新客户信息
        $("#rightContainer").load("project/proinfo/editComInfo.html", function () {
            findComInfo($certusUtils, $$scope, kid);
        });
    } else if (flag == 8) {
        //添加联系人
        $("#rightContainer").load("project/proinfo/addLxr.html", function () {
            addLxr($certusUtils, kid);
        });
    } else if (flag == 9) {
        //修改联系人
        $("#rightContainer").load("project/proinfo/updateLxr.html", function () {
            updateLxr($certusUtils, kid);
        });
    } else if (flag == 10) {
        //更新项目目标
        $("#rightContainer").load("proinfo/edit/edit-target.html",function () {
            findTarById(kid);
        });
    }else if (flag == "10-1") {
        //新增项目目标
        $("#rightContainer").load("proinfo/edit/add-target.html");
    } else if (flag == 50) {
        //项目公告
        $("#rightContainer").load("project/notice.html", function () {
            findNoticeList();
        });
    }
    else if (flag == 49) {
        //项目纪要
        $("#rightContainer").load("project/meeting.html", function () {
            findMeetList();
        });
    }
    else if (flag == 48) {
        //添加项目公告
        $("#rightContainer").load("proinfo/edit/edit-notice.html");
    }
    else if (flag == 47) {
        //编辑项目公告
        $("#rightContainer").load("proinfo/edit/edit-notice1.html", function () {
            toEditNotice(kid);
        });
    }
    else if (flag == 46) {
        //编辑项目公告
        $("#rightContainer").load("proinfo/edit/edit-meeting.html");
    }
    else if (flag == 45) {
        //编辑项目公告
        $("#rightContainer").load("proinfo/edit/edit-meeting1.html", function () {
            toEditMeeting(kid);
        });
    }
    else if (flag == 44) {
        //线索信息
        $("#rightContainer").load("proinfo/clues.html", function () {
            findStageInfo();
        });
    }
    else if (flag == 43) {
        //线索信息 审批记录
        $("#rightContainer").load("proinfo/clues-sp.html");
    }
    else if (flag == 42) {
        //立项信息
        $("#rightContainer").load("proinfo/setup.html", function () {
            findLxInfo();
        });
    }
    else if (flag == 41) {
        //立项信息
        $("#rightContainer").load("proinfo/setup-sp.html");
    }
    else if (flag == 40) {
        //添加风险
        $("#rightContainer").load("proinfo/edit/add-risk.html");
    }
    else if (flag == 39) {
        //修改风险
        $("#rightContainer").load("proinfo/edit/edit-risk.html", function () {
            findRiskInfo(kid);
        });
    }
    else if (flag == 38) {
        //添加项目整体进展
        // $("#rightContainer").load("proinfo/edit/add-prg.html");
        $("#rightContainer").load("proinfo/edit/nadd-prg.html");
    }
    else if (flag == 37) {
        //修改项目整体进展
        $("#rightContainer").load("proinfo/edit/edit-prg.html", function () {
            findReportInfo(kid);
        });
    }
    else if (flag == 36) {
        //添加决策上报
        $("#rightContainer").load("proinfo/edit/add-making.html");
    }
    else if (flag == 35) {
        //修改决策上报
        $("#rightContainer").load("proinfo/edit/edit-making.html", function () {
            findDecisionInfo(kid);
        });
    }
    else if (flag == 34) {
        //添加项目变更
        $("#rightContainer").load("proinfo/edit/add-change.html");
    }
    else if (flag == "33-1") {
        //查看项目变更详情
        $("#rightContainer").load("proinfo/modifyDetail.html", function () {
            ckDetail(kid);
        });
    }else if (flag == 33) {
        //修改
        $("#rightContainer").load("proinfo/edit/edit-change.html", function () {
            findChangInfo(kid);
        });
    } else if (flag == 32) {
        //添加需求信息
        $("#rightContainer").load("project/proinfo/addDemand.html");
    } else if (flag == 31) {
        //添加需求信息
        $("#rightContainer").load("project/proinfo/addProblem.html");
    } else if (flag == 30) {
        //预算报销 - 预算信息
        $("#rightContainer").load("proinfo/cost.html", function () {
            findCostInfo();
        });
    } else if (flag == 29) {
        //预算报销 - 报销信息
        $("#rightContainer").load("proinfo/costbx.html", function () {
            findCostbxInfo();
        });
    } else if (flag == 28) {
        //预算报销 - 报销信息 - 查看
        $("#rightContainer").load("proinfo/edit/edit-cost.html", function () {
            findCostDetail(kid);
        });
    } else if (flag == 27) {
        //项目变更
        $("#rightContainer").load("proinfo/proModify.html");
    } else if (flag == 26) {
        //资产管理
        $("#rightContainer").load("proinfo/proassets.html", function () {
            findProAssets();
        });
    } else if (flag == 25) {
        //资产管理--查看
        $("#rightContainer").load("proinfo/edit/edit-assets-2.html", function () {
            toDetail(kid);
        });
    }else if (flag == 24) {
        //客户管理-拜访记录
        $("#rightContainer").load("project/proinfo/visit.html",function () {
            findVisit();
        });
    }else if (flag == 23) {
        //客户管理-新增客户
        $("#rightContainer").load("project/proinfo/add-customer.html",function () {
            addCustomer();
        });
    }else if(flag==22){
        //客户管理-客户拜访记录-新增拜访记录
        $("#rightContainer").load("project/proinfo/add-ctlog.html",function () {
            addVisit();
        });
    }else if(flag==21){
        //客户管理-客户拜访记录-新增拜访记录
        $("#rightContainer").load("project/proinfo/edit-ctlog.html",function () {
            editVisit(kid);
        });
    }
    else if (flag == 51) {
        //问题管理页面
        $("#rightContainer").load("project/proinfo/problem.html", function () {
            findProblemList($CertusJsonAjax);
        });
    } else if (flag == 52) {
        //问题管理页面
        $("#rightContainer").load("project/proinfo/proDemand.html", function () {
            findDemanList($CertusJsonAjax);
        });
    }
    else if (flag == 11) {
        //okr 添加标准动作页面
        $("#rightContainer").load("proinfo/edit/edit-okr-1.html", function () {
            findOkrList($certusUtils);
        })
    } else if (flag == 12) {
        //okr 添加子任务页面
        $("#rightContainer").load("proinfo/edit/edit-key-1.html", function () {
            findTaskList($certusUtils);
        })
    }else if (flag==101){
        //验收信息
        $("#rightContainer").load("proinfo/accp.html",function () {
            fundAccps();
        });
    }else if (flag==102){
        //开票回款信息
        $("#rightContainer").load("proinfo/accppay.html",function () {
            findKpinfo();
        });
    }else if (flag==103){
        //添加验收信息
        toAddAccps();
    }else if (flag==104){
        //添加开票信息
        $("#rightContainer").load("proinfo/edit/addkpinfo.html",function () {
            addKpinfo();
        });
    }
    else if (flag==105){
        //添加回款记录
        $("#rightContainer").load("proinfo/edit/add-recble.html",function () {
            addHkinfo();
        });
    }else if (flag==106){
        //添加本周投标情况和下周预测情况
        $("#rightContainer").load("proinfo/edit/add-tbyc.html");
    }else if (flag==107){
        //添加本周投标情况和下周预测情况
        $("#rightContainer").load("proinfo/edit/edit-tbyc.html",function () {
            edittbyc(kid);
        });
    }else if(flag==108){
        //客户管理-客户拜访记录-新增拜访记录
        $("#rightContainer").load("proinfo/okradd-ctlog.html");
    }else if(flag==109){
        //okr管理-客户拜访记录-编辑拜访记录
        $("#rightContainer").load("proinfo/okredit-ctlog.html",function () {
            editVisit(kid);
        });
    }
    else if (flag == 13) {
        //okr 更新子任务进展页面
        $("#rightContainer").load("proinfo/edit/edit-children.html", function () {
            findHistPlans(kid);
        })
    } else if (flag == 14) {
        //跳转 投标信息 页面
        disBidPageInProj();
    } else if (flag == 15) {
        //跳转 成员 权限 列表 页面
        disProStaffAndEidtAuthority();
    }
}
function toPutUtils(CertusFormAjax, $scope, $http, $interval, CertusJsonAjax, $routeParams, fileListService,backlogPersonList,$timeout) {
    $certusUtils       = CertusFormAjax;
    $$scope            = $scope;
    $$http             = $http;
    $$interval         = $interval;
    $$timeout   = $timeout;
    $CertusJsonAjax    = CertusJsonAjax;
    $fileListService   = fileListService;
    $backlogPersonList = backlogPersonList

    // $scope.isHasKHGL=true;

    //项目详情 投标信息
    $scope.toBidInfo = function () {
        disBidPageInProj();
    }

    //项目详情页 成员权限
    $scope.disProStaffAndEidtAuthority = function () {
        disProStaffAndEidtAuthority();
    }

    //项目详情页 合同信息
    $scope.projContactInfo = function () {
        disProjContactInfo();
    }

    //项目文档信息 管理
    $scope.projDocumentSubPage = function () {
        disprojDocumentSubPage();
    }

    //项目文档客户 界面管理
    $scope.projDocumentCusPage = function () {
        disprojDocumentCusPage();
    }
    //打卡 请购页面
    $scope.disBuyingManager = function(){
        disBuyingManager1()
    }

    if (proId == 0) {
        var str = $routeParams.id.split("_");

        proId = str[0];
        //是否是直接跳转到okr计划分配

        var isTurn = str[1];
        if (isTurn == 0) {
            toLoadHtml(1);
        } else {
            toLoadHtml(4, 2);
        }

        $certusUtils.ajax("findPros",{"proId":proId},function(response){
            $$scope.proName = response.data.proName;
        })
        //获取登录人信息
        $certusUtils.ajax("getUserId", {}, function (res) {
            userId = res.data;
        });

        //初始化项目信息
        $certusUtils.ajax("loadProInfo", {"proId": proId}, function (res) {
            proBaseInfo = res.data;
            projectType = proBaseInfo.proType;
            // if (projectType=='XS'){
            //     $scope.isHasKHGL=false;
            // }
            //项目详情页 左边栏 权限控制
            $certusUtils.ajax("leftMenuAuthority", {"projType": projectType, "projId": proId}, function (res) {
                if (res.data) {
                    leftMenu        = res.data;
                    $scope.leftMenu = res.data;
                }
            });
        });
    }
}
//项目信息页面跳转的方法，共用一个angularjs服务
function disBidPageInProj() {
    $("#rightContainer").empty();
    $$http({
        url     : "proinfo/edit/edit-bid.html",
        method  : 'GET',
        data    : {},
        dataType: "application/json"
    }).then(function (a) {
        $$scope.htmlxx  = a.data;
        $CertusFormAjax = $certusUtils;
    }, function (b) {
    })
}

function tab2() {
    $("#rightContainer").empty();
    $$http({
        // url: "proinfo/edit/edit-compact.html",
        url     : "proinfo/projPact-record.html",
        method  : 'GET',
        data    : {},
        dataType: "application/json"
    }).then(function (a) {
        $$scope.htmlxx  = a.data
        $CertusFormAjax = $certusUtils;
    }, function (b) {
    })
}

//项目详情 展示 成员信息
function disProStaffAndEidtAuthority() {
    $("#rightContainer").empty();
    $$http({
        url     : "proinfo/members.html",
        method  : 'GET',
        data    : {},
        dataType: "application/json"
    }).then(function (a) {
        $$scope.htmlxx  = a.data
        $CertusFormAjax = $certusUtils;
    }, function (b) {
    })
}

//项目详情  展示 合同基本信息
function disProjContactInfo() {
    $("#rightContainer").empty();
    $$http({
        // url: "proinfo/edit/edit-compact.html",
        url     : "proinfo/projPact.html",
        method  : 'GET',
        data    : {},
        dataType: "application/json"
    }).then(function (a) {
        $$scope.htmlxx  = a.data
        $CertusFormAjax = $certusUtils;
    }, function (b) {
    })
}
//展示 文档管理 字页面
function disprojDocumentSubPage() {
    debugger;
    $("#rightContainer").empty();
    $$http({
        // url: "proinfo/edit/edit-compact.html",
        url     : "project/proinfo/Document.html",
        method  : 'GET',
        data    : {},
        dataType: "application/json"
    }).then(function (a) {
        $$scope.htmlxx  = a.data
        $CertusFormAjax = $certusUtils;
    }, function (b) {
    })
}

function disprojDocumentCusPage() {
    $("#rightContainer").empty();
    $$http({
        // url: "proinfo/edit/edit-compact.html",
        url     : "project/proinfo/Document-custom.html",
        method  : 'GET',
        data    : {},
        dataType: "application/json"
    }).then(function (a) {
        $$scope.htmlxx  = a.data
        $CertusFormAjax = $certusUtils;
    }, function (b) {
    })
}
//打开请购管理 页面
function disBuyingManager1(){
    $("#rightContainer").empty();
    $$http({
        // url: "proinfo/edit/edit-compact.html",
        url     : "project/proinfo/buyingDatagrid.html",
        method  : 'GET',
        data    : {},
        dataType: "application/json"
    }).then(function (a) {
        $$scope.htmlxx  = a.data
        $CertusFormAjax = $certusUtils;
    }, function (b) {
    })
}

$('.nav-pills li').on('click',function(){
    $('.nav-pills li').removeClass('active');
    $(this).addClass('active');
});